package com.fr.chart.shape3d;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ColorInfo;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.SoloGlyph;
import com.fr.chart.math.Object3D;
import com.fr.chart.math.Projection;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Float;
import java.util.ArrayList;
import java.util.List;

public class FoldLine3D extends SoloGlyph
  implements Object3D
{
  private static final long serialVersionUID = -5271643180557390028L;
  public static final String XML_TAG = "FoldLine3D";
  private float z = 0.0F;
  private float deep = 60.0F;
  private Projection projection = new Projection();
  private List point_list = new ArrayList();
  private ColorInfo colorInfo = new ColorInfo();

  public FoldLine3D()
  {
  }

  public FoldLine3D(float paramFloat1, float paramFloat2)
  {
    setZ(paramFloat1);
    setDeep(paramFloat2);
  }

  public FoldLine3D(double paramDouble1, double paramDouble2)
  {
    setZ((float)paramDouble1);
    setDeep((float)paramDouble2);
  }

  public void moveTo(float paramFloat1, float paramFloat2)
  {
    getPoint_list().clear();
    getPoint_list().add(new Point2D.Float(paramFloat1, paramFloat2));
  }

  public void lineTo(float paramFloat1, float paramFloat2)
  {
    getPoint_list().add(new Point2D.Float(paramFloat1, paramFloat2));
  }

  public void closePath()
  {
    if (getPoint_list().size() > 0)
      getPoint_list().add(getPoint_list().get(0));
  }

  public void draw(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    GeneralPath[] arrayOfGeneralPath = getGeneralPaths();
    for (int i = 0; i < arrayOfGeneralPath.length; ++i)
      getColorInfo().paint(localGraphics2D, arrayOfGeneralPath[i]);
  }

  private GeneralPath[] getGeneralPaths()
  {
    ArrayList localArrayList = new ArrayList();
    for (int i = 0; i < getPoint_list().size() - 1; ++i)
    {
      double d1 = ((Point2D)getPoint_list().get(i)).getX();
      double d2 = ((Point2D)getPoint_list().get(i)).getY();
      double d3 = ((Point2D)getPoint_list().get(i + 1)).getX();
      double d4 = ((Point2D)getPoint_list().get(i + 1)).getY();
      Point2D localPoint2D1 = getProjection().projectee(d1, d2, getZ());
      Point2D localPoint2D2 = getProjection().projectee(d3, d4, getZ());
      Point2D localPoint2D3 = getProjection().projectee(d3, d4, getZ() - getDeep());
      Point2D localPoint2D4 = getProjection().projectee(d1, d2, getZ() - getDeep());
      GeneralPath localGeneralPath = new GeneralPath();
      localGeneralPath.moveTo((float)localPoint2D1.getX(), (float)localPoint2D1.getY());
      localGeneralPath.lineTo((float)localPoint2D2.getX(), (float)localPoint2D2.getY());
      localGeneralPath.lineTo((float)localPoint2D3.getX(), (float)localPoint2D3.getY());
      localGeneralPath.lineTo((float)localPoint2D4.getX(), (float)localPoint2D4.getY());
      localGeneralPath.closePath();
      localArrayList.add(localGeneralPath);
    }
    return ((GeneralPath[])localArrayList.toArray(new GeneralPath[localArrayList.size()]));
  }

  public Shape getShape()
  {
    GeneralPath localGeneralPath = new GeneralPath();
    GeneralPath[] arrayOfGeneralPath = getGeneralPaths();
    for (int i = 0; i < arrayOfGeneralPath.length; ++i)
      localGeneralPath.append(arrayOfGeneralPath[i], false);
    return localGeneralPath;
  }

  public void setZ(float paramFloat)
  {
    this.z = paramFloat;
  }

  public float getZ()
  {
    return this.z;
  }

  public void setProjection(Projection paramProjection)
  {
    this.projection = paramProjection;
  }

  public Projection getProjection()
  {
    return this.projection;
  }

  public void setDeep(float paramFloat)
  {
    this.deep = paramFloat;
  }

  public float getDeep()
  {
    return this.deep;
  }

  public void setPoint_list(List paramList)
  {
    this.point_list = paramList;
  }

  public List getPoint_list()
  {
    return this.point_list;
  }

  public void setColorInfo(ColorInfo paramColorInfo)
  {
    this.colorInfo = paramColorInfo;
  }

  public ColorInfo getColorInfo()
  {
    return this.colorInfo;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("z")) != null)
          setZ(Float.valueOf(str2).floatValue());
        if ((str2 = paramXMLableReader.getAttr("deep")) != null)
          setDeep(Float.valueOf(str2).floatValue());
      }
      else if (str1.equals("Projection"))
      {
        this.projection = ((Projection)paramXMLableReader.readXMLObject(new Projection()));
      }
      else if (str1.equals("PointList"))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final FoldLine3D this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              String str = paramXMLableReader.getTagName();
              if (str.equals("Point"))
              {
                Point2D.Float localFloat = new Point2D.Float(Float.valueOf(paramXMLableReader.getAttr("x")).floatValue(), Float.valueOf(paramXMLableReader.getAttr("y")).floatValue());
                FoldLine3D.access$000(this.this$0).add(localFloat);
              }
            }
          }
        });
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("FoldLine3D").startTAG("Attr").attr("z", getZ()).attr("deep", getDeep()).end();
    if (getProjection() != null)
      getProjection().writeXML(paramXMLPrintWriter);
    if ((this.point_list != null) && (this.point_list.size() > 0))
    {
      paramXMLPrintWriter.startTAG("PointList");
      for (int i = 0; i < this.point_list.size(); ++i)
      {
        Point2D localPoint2D = (Point2D)getPoint_list().get(i);
        paramXMLPrintWriter.startTAG("Point").attr("x", localPoint2D.getX()).attr("y", localPoint2D.getY()).end();
      }
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof FoldLine3D))
      return false;
    FoldLine3D localFoldLine3D = (FoldLine3D)paramObject;
    if (localFoldLine3D.getZ() != getZ())
      return false;
    if (localFoldLine3D.getDeep() != getDeep())
      return false;
    if (!(Equals.equals(localFoldLine3D.getProjection(), getProjection())))
      return false;
    if (localFoldLine3D.getPoint_list().size() != getPoint_list().size())
      return false;
    for (int i = 0; i < localFoldLine3D.getPoint_list().size(); ++i)
      if (!(Equals.equals(localFoldLine3D.getPoint_list().get(i), getPoint_list().get(i))))
        return false;
    return true;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("deep", this.deep);
    localJSONObject.put("z", this.z);
    localJSONObject.put("point_list", this.point_list);
    if (this.projection != null)
      localJSONObject.put("projection", this.projection.toJSONObject());
    if (this.colorInfo != null)
      localJSONObject.put("colorInfo", this.colorInfo.toJSONObject());
    return localJSONObject;
  }

  static List access$000(FoldLine3D paramFoldLine3D)
  {
    return paramFoldLine3D.point_list;
  }
}